import { uuid } from "./uuid"

const id: string = uuid()  // 子系统比作用户  yhid
function handleMessage(event: MessageEvent) {
  if (event.source == window) return
  const { data } = event
  window.removeEventListener('message', handleMessage)
  if (data.id === id) {
    return data
  }
}
export function getParentsInfo(fun: string = id): Promise<any> {
  return (new Promise((resolve, reject) => {
    window.parent.postMessage(fun, '*'); // 确定父页面的URL
    window.addEventListener("message", resolve)
  }) as Promise<MessageEvent>).then(handleMessage)
}